﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.EnterpriseServices;

namespace YZT.Helper
{
    [Serializable]
    public class MapConfig
    {
        public MapConfig()
        {
        }
        public Point Center = new Point();
        public string SpatialReferenceType;
        public string SpatialReferenceValue;
        public Extent Extent = new Extent();
        public int StartZoomLevel;
        public LocateConfig LocateConfig = new LocateConfig();
        public List<string> OptionNames = new List<string>();
        public List<string> OptionValues = new List<string>();
        public string GeometryServiceUrl = "";
        public bool ShowInnerLayersInLayersControl = false;
        public List<Layer> Layers = new List<Layer>();
        #region 序列化
        public static MapConfig Deserialize(string path)
        {
            System.Xml.XmlReader reader = null;

            try
            {
                reader = System.Xml.XmlReader.Create(path);

                System.Xml.Serialization.XmlSerializer sr = new System.Xml.Serialization.XmlSerializer(typeof(MapConfig));

                object obj = sr.Deserialize(reader);

                reader.Close();
                sr = null;

                MapConfig ds = null;

                if (obj != null)
                    ds = (MapConfig)obj;

                return ds;
            }
            catch (Exception err)
            {
                throw err;
            }
            finally
            {
                reader = null;
            }
        }
        public static bool Serialize(string path, MapConfig obj)
        {
            System.Xml.XmlWriter writer = null;

            try
            {
                writer = System.Xml.XmlWriter.Create(path);

                System.Xml.Serialization.XmlSerializer sr = new System.Xml.Serialization.XmlSerializer(typeof(MapConfig));

                sr.Serialize(writer, obj);

                writer.Flush();

                writer.Close();

                return true;
            }
            catch (Exception err)
            {
                throw err;
            }
            finally
            {
                writer = null;
            }
        }
        #endregion

    }
    [Serializable]
    public class Point
    {
        public Point()
        {
        }
        public Point(double x, double y)
        {
            // TODO: Complete member initialization
            this.X = x;
            this.Y = y;
        }
        public double X;
        public double Y;
    }
    [Serializable]
    public class Extent
    {
        public Extent()
        {
        }
        public Extent(double left, double bottom, double right, double top)
        {
            // TODO: Complete member initialization
            this.Left = left;
            this.Bottom = bottom;
            this.Right = right;
            this.Top = top;
        }
        public double Left;
        public double Bottom;
        public double Right;
        public double Top;
    }
    [Serializable]
    public class Layer:IComparable
    {
        public Layer()
        {
        }
        public string Name;
        public string Catalog;
        public string Cpation;
        public string Url;
        public string LayerType;
        public bool QueryAble;
        public bool Visible = true;
        public int Opacity = 100;
        public bool Load = true;
        public int LayerIndex = 1;
        public bool BaseLayer = false;
        public bool ShowInnerLayersInLayersControl = false;
        public List<InnerLayer> InnerLayers = new List<InnerLayer>();

        public int CompareTo(object obj)
        {
            if (obj == null)
                return -1;
            Layer l=obj as Layer;
            return LayerIndex.CompareTo(l.LayerIndex);
        }
    }
    [Serializable]
    public class LayerType
    {
        public static string ArcGISDynamicMapServiceLayer = "ArcGISDynamicMapServiceLayer";
        public static string ArcGISImageServiceLayer = "ArcGISImageServiceLayer";
        public static string ArcGISTiledMapServiceLayer = "ArcGISTiledMapServiceLayer";
        public static string WMSLayer = "WMSLayer";
        public static string WMTSLayer = "WMTSLayer";
        public static string KMLLayer = "KMLLayer";
        public static string FeatureLayer = "FeatureLayer";

    }
    [Serializable]
    public class SpatialReferenceType
    {
        public static string wkt="wkt";
        public static string wkid="wkid";
        public static string json="json";
    }
    [Serializable]
    public class InnerLayer
    {
        public InnerLayer()
        {
        }
        public bool QueryAble;
        public bool Visible = true;
        public List<string> FieldNames = new List<string>();
        public List<string> FieldCaptions = new List<string>();
        public string Name;
        public bool ShowInLayersControl = false;
    }



    [Serializable]
    public class LocateConfig
    {
        public LocateConfig()
        {
        }
        public List<Model> Models = new List<Model>();
    }
    [Serializable]
    public class Model
    {
        public Model()
        {
        }
        public string Name;
        public string LayerName;
        public string InnerLayerName;

    }
}